<?php

require_once '../include/common.inc.php';

if (!checkAdmin()) {
    header("LOCATION:index.php");
    exit;
}

$menu_index = 1;
$page_title = 'JANSEN';

$tmp_ary = array();
$out_ary = array();

getMyParam('iid');
$sql = "SELECT `name` FROM `inventory` WHERE id='$iid'";
$rs = $db->get_one($sql);
if (empty($rs)) {
    echo "<script>alert('Inventory not exist.');location.href='product.php'</script>";
    exit;
}
$inventory_name = $rs['name'];

$guide_message = 'Product | Basic Infomation | ' . $inventory_name . ' | Select Inventory';

$sql = "SELECT c.`category_id`, i.`product_id` FROM `product_inventory` i , `product_category` c WHERE  i.inventory_id='$iid' AND c.product_id=i.product_id";
$query = $db->query($sql);
while($rs1 = $db->fetch_array($query)) {
    $tmp_ary[] = $rs1['category_id'];
}
$tmp_ary = array_unique($tmp_ary);

if (!empty($tmp_ary)) {
    $tmp_str = implode(",", $tmp_ary);
    $sql = "SELECT `id`, `pic`, `name`, `description` FROM category WHERE `id` IN (" . $tmp_str . ") ORDER BY `seq` ASC";
    $query = $db->query($sql);
    while($rs = $db->fetch_array($query)) {
        $out_ary[] = $rs;
    }
}


require_once PrintEot('a_header');
require_once PrintEot('a_p_category_list');
require_once PrintEot('a_footer');

?>